
jQuery(document).ready(function() {

    $('#createForm').validate({
        rules:{
            username: {
                required: true,
                username: true,
                rangelength: [3,22]
            },
            password: {
                required: true,
                minlength: 6
            },
            confirmPassword: {
                required: true,
                equalTo: "#password"
            }
        },
        messages: {
            username: {
                //remote: "用户名已存在！"
            },
            confirmPassword: {
                equalTo: "两次输入的密码不一致"
            }
        },
        errorPlacement: errorPlacement,
        success: success,
        submitHandler: function(form){
            waitMessage();
            $.ajax({
                    type: "post",
                    url: path+"/admin/create",
                    data: {
                        username: $('#username').val(),
                        password: $('#password').val()
                    },
                    dataType: 'json',
                    success: function(data){
                        if(data.success){
                           successMessage("操作成功！");
                        }
                        else errorMessage("操作失败：" + data.msg);
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown){
                        errorMessage("操作失败，错误代码： " + XMLHttpRequest.status);
                    }
                }
            );
        }
    });
});

